# coding=utf8
from ml.knn.KNN import *


def file2matrix(filename):
    fr = open(filename)
    arr_lines = fr.readlines()
    num_lines = len(arr_lines)
    data_mat = zeros((num_lines, 3))

    class_label_vec = []
    i = 0
    for line in arr_lines:
        # remove line's 'enter' and split.
        line = line.strip()
        list_from_line = line.split("\t")

        # put pre 3 data into mat.
        data_mat[i, :] = list_from_line[0:3]

        # put last data into label vector.
        class_label_vec.append(int(list_from_line[-1]))
        i += 1

    return data_mat, class_label_vec
